using System;
using System.Runtime.CompilerServices;

namespace  Hotel.UI.Facade
{
    /// <summary>
    /// 接口返回数据结果基类
    /// </summary>
    public class BaseResultJson
    {
        /// <summary>
        /// 错误代码
        /// </summary>
        public int code
        {
            get;
            set;
        }

        /// <summary>
        /// 如果不成功，返回的错误信息
        /// </summary>
        public string info
        {
            get;
            set;
        }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool success
        {
            get
            {
                return code == 200;
            }
        }
        /// <summary>
        /// 接口响应数据
        /// </summary>
        public dynamic data { get; set; }
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public BaseResultJson()
        {


            this.code = -1;
            this.info = "";
        }

        /// <summary>
        /// 普通参数构造
        /// </summary>
        /// <param name="info">错误信息</param>
        /// <param name="success">是否成功</param>
        /// <param name="errcode">错误代码</param>
        public BaseResultJson(string info, bool success = false, int errcode = 0)
        {


            this.info = info;
            this.code = errcode;
        }

        /// <summary>
        /// 通过异常对象进行构造
        /// </summary>
        /// <param name="ex">异常对象</param>
        /// <param name="errcode">错误代码</param>
        public BaseResultJson(Exception ex, int errcode = 0)
        {


            this.info = ex.Message;
            this.code = errcode;
        }
    }
}